package DataStructure;

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Queue;

class Data1100
{	public int index,id,pt;
	public Data1100(int ix,int i,int p)
	{	index=ix;id=i;pt=p;
	}
	public char[] ToString()
	{	return (id+" "+pt+"\n").toCharArray();
	}
}
class Solver1100
{	int n;
	Comparator<Data1100> CMP=new Comparator<Data1100>()
	{	public int compare(Data1100 d1,Data1100 d2)
		{	if (d1.pt!=d2.pt) return d2.pt-d1.pt;
			else return d1.index-d2.index;
		}
	};
	Queue<Data1100> Rec;
	
	public void Input() throws IOException
	{	StreamTokenizer in=new StreamTokenizer(new InputStreamReader(System.in));
		in.nextToken();n=(int)in.nval;
		Rec=new PriorityQueue<Data1100>(n,CMP);
		for (int i=1;i<=n;i++)
		{	in.nextToken();int id=(int)in.nval;
			in.nextToken();int pt=(int)in.nval;
			Rec.add(new Data1100(i,id,pt));
		}
	}
	public void Solve() throws IOException
	{	Input();
		char[] Rs=new char[n*13];
		int mark=0;
		while (!Rec.isEmpty())
		{	char[] tmp=Rec.remove().ToString();
			System.arraycopy(tmp,0,Rs,mark,tmp.length);
			mark+=tmp.length;
		}
		System.out.println(new String(Rs,0,mark));
	}
	
}
public class P1100
{	public static void main(String[] args) throws IOException
	{	Solver1100 solver=new Solver1100();
		solver.Solve();
	}
}
